package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.RoleItemInfoModel;
import com.iris.live.services.data.models.RoleModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by yitianle on 2017/8/10.
 */
public interface RoleRepository extends JpaRepository<RoleModel,Integer> {

    /**
     * 获取集团角色
     * @return
     */
    @Query("select u from RoleModel u where u.isGroup = 2")
    List<RoleModel>  findRoleListByGroups();

    /**
     * 获取大区角色
     * @return
     */
    @Query("select u from RoleModel u where u.isGroup = 3")
    List<RoleModel>  findRoleListByGroup();

    /**
     * 获取集团大区角色
     * @return
     */
    @Query("select u from RoleModel u where u.isGroup != 1 and u.isGroup != 0")
    List<RoleModel>  findRoleListByGroupNoAdmin();


    @Query("select u from RoleModel u where u.isGroup != ?1 and u.roleName = ?2")
    RoleModel getRoleExists(Integer groupType, String role);

    /**
     * 获取经销商角色
     * @return
     */
    @Query("select u from RoleModel u where u.isGroup = 0")
    List<RoleModel>  findRoleListByDealer();


    /**
     * 根据角色名称查询角色信息
     * @param role
     * @return
     */
    @Query("select u from RoleModel u where  u.roleName = ?1")
    RoleModel getRoleInfo( String role);


}
